package com.alibaba.aone.casestudy.module.screen;

import static com.alibaba.citrus.turbine.util.TurbineUtil.getTurbineRunData;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.aone.casestudy.common.WebConstant;
import com.alibaba.aone.casestudy.common.entity.AoneDepart;
import com.alibaba.aone.casestudy.common.entity.AoneUser;
import com.alibaba.aone.casestudy.service.AoneUserService;
import com.alibaba.citrus.turbine.Context;
import com.alibaba.citrus.turbine.TurbineRunDataInternal;

public class Index {

	@Autowired
	private HttpServletRequest request;
	@Autowired
	private AoneUserService userService;

	public void execute(Context context) {

		TurbineRunDataInternal rundata = (TurbineRunDataInternal) getTurbineRunData(request);
		String cookie = rundata.getCookies().getString(
				WebConstant.AONE_COOKIE_LOGIN_NAME);
		context.put("loginName", cookie);

		List<AoneDepart> departList = userService.getAllDepart();
		

		context.put("departList", departList);

		AoneUser user = userService.getAoneUserByAccount(cookie);
		System.out.println("<---------------------------------------------------------------->");
		System.out.println(user.getDepartment());
		System.out.println("<---------------------------------------------------------------->");

		context.put("aoneUser", user);
	}
}
